package com.longsunhd.yum.buffalo.util;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.RequiresApi;
import android.support.v4.content.ContextCompat;

import com.longsunhd.yum.buffalo.R;
import com.longsunhd.yum.buffalo.bean.UserInfoBean;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import cn.addapp.pickers.listeners.OnItemPickListener;
import cn.addapp.pickers.listeners.OnSingleWheelListener;
import cn.addapp.pickers.picker.SinglePicker;

/**
 * 作者：黄宣淇
 * 时间：2021/5/10 0010
 * 如何代码没有备注，一个月后，只有你和上帝知道--鲁迅
 */
public class SinglePickerUtil {
    @RequiresApi(api = Build.VERSION_CODES.N)
    public  static <C extends ISinglePickerBean> void SinglePickeerUtils(Activity activity,  ArrayList<C> list , final Handler handler){
        Message message=new Message();
        List<String> list1=list.stream().map(s->s.getName()).collect(Collectors.toList());
        SinglePicker<String> picker = new SinglePicker<String>(activity, list1);
        picker.setCanLoop(false);//不禁用循环
        picker.setLineVisible(true);
        picker.setLineColor(ContextCompat.getColor(activity, R.color.main_color));
        picker.setTextSize(30);
        picker.setSelectedIndex(0);
        picker.setOuterLabelEnable(true);
        picker.setSelectedTextColor(ContextCompat.getColor(activity,R.color.main_color));//前四位值是透明度
        picker.setUnSelectedTextColor(Color.BLACK);
        picker.setOnSingleWheelListener(new OnSingleWheelListener() {
            @Override
            public void onWheeled(int index, String item) {
                // mTvNoon.setText("index=" + index + ", item=" + item);
//                ToastUtils.showShort("index=" + index + ", item=" + item);
                handler.sendMessage(message);
            }
        });
        picker.setOnItemPickListener(new OnItemPickListener<String>() {
            @Override
            public void onItemPicked(int index, String item) {

//                ToastUtils.showShort("index=" + index + ", item=" + item);
            }
        });
        picker.show();
    }
    public interface ISinglePickerBean{
        String getName();
    }
}
